package com.clayecloud.common.admin.controller;

import com.clayecloud.common.annotation.NoAuthorization;
import com.clayecloud.common.utils.GlobalFileUtil;
import com.clayecloud.common.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @author ClayeLink
 * @date 2022/3/21 22:34
 */
@RestController
@RequestMapping("/admin")
@Api(tags = "文件上传模块")
public class AdminFileController {

    @Value("${file.file-path}")
    private String filePath;

    @Value("${hostUrl}")
    private String hostUrl;

    @PostMapping("/file")
    @NoAuthorization
    @ApiOperation("管理端上传文件接口")
    public MessageUtil fileUpload(@RequestPart @RequestParam("files") MultipartFile[] files) throws IOException {
        if (files.length>0) {
            String rs= GlobalFileUtil.saveFileToTempDir(filePath, hostUrl, files);
            return MessageUtil.success(null).add(rs);

        }
        return MessageUtil.fail("没有读取到您的上传文件信息");
    }

}
